/**
 * 
 */
package mines.fila3.letstalk.data;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * This class allows to define a message on our application. A message can't be
 * modify, except for its reading value.
 * 
 * @author aminaud & qmahe
 * 
 */
public class MessageLetstalk implements Parcelable {

	private String content = "";
	private String author = "";
	private boolean read = false;

	/**
	 * 
	 * @param author
	 * @param content
	 */
	public MessageLetstalk(String author, String content) {
		read = false;

		if (author != null)
			this.author = author;

		if (content != null)
			this.content = content;
	}

	public MessageLetstalk(Parcel in) {
		read = in.readByte() != 0;
		String[] strings = new String[2];
		in.readStringArray(strings);
		author = strings[0];
		content = strings[1];
	}

	/**
	 * @return the message content.
	 */
	public String getContent() {
		return content;
	}

	/**
	 * @return the message author
	 */
	public String getAuthor() {
		return author;
	}

	/**
	 * @return true if the message has read, otherwise false.
	 */
	public boolean isRead() {
		return read;
	}

	/**
	 * This method is protected to force the developer to use the method
	 * "setReadItem" in ListMessages.
	 * 
	 * @param read
	 *              true if the message has been read.
	 */
	protected void setRead(boolean read) {
		this.read = read;
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeByte((byte) (read ? 1 : 0));
		String[] strings = { author, content };
		dest.writeStringArray(strings);
	}

	public static final Creator<MessageLetstalk> CREATOR = new Creator<MessageLetstalk>() {

		public MessageLetstalk createFromParcel(Parcel in) {
			return new MessageLetstalk(in);
		}

		public MessageLetstalk[] newArray(int size) {
			return new MessageLetstalk[size];
		}
	};

}
